package example.discard;

import java.nio.ByteBuffer;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class DiscardClientHander extends SimpleChannelInboundHandler<Object> {
 
		ByteBuf content;
	
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
		System.out.println("read0");
		
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("active");
		// Initialize the message.
		content =  ctx.alloc().directBuffer(DiscardClient.SIZE).writeChar(123456);
	
		
		//send the message.
		ctx.writeAndFlush(content);
		
		 
	}
	
	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		content.release();
		System.out.println("conn inactive");
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		 // Close the connection when an exception is raised.
		cause.printStackTrace();
		ctx.close();
	}
	

}
